/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.landmark;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author computer
 */
public class RenameDirFileGUI extends RenameDirFiles{
    JFileChooser fc;

    /**
     * Creates new form RenameDirFileGUI
     */
    public RenameDirFileGUI() {
        initComponents();
        fc = new JFileChooser();
        
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setMultiSelectionEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtInputFolder = new javax.swing.JTextField();
        btnInputFolder = new javax.swing.JButton();
        txtPrefix = new javax.swing.JTextField();
        cmbExtension = new javax.swing.JComboBox();
        btnChangeImageName = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        txtRemPrefix = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtRemSuffix = new javax.swing.JTextField();

        setBackground(new java.awt.Color(0, 113, 187));
        setFont(new java.awt.Font("Cambria", 0, 11)); // NOI18N

        txtInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnInputFolder.setText("...");
        btnInputFolder.setToolTipText("Select the folder with images");
        btnInputFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputFolderActionPerformed(evt);
            }
        });

        txtPrefix.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        cmbExtension.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        cmbExtension.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SELECT", "_MAIN", "_SW", "_LG", "_SM", "_MOD" }));

        btnChangeImageName.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnChangeImageName.setText("Rename Files");
        btnChangeImageName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangeImageNameActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Add Image Prefix :");

        jLabel2.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Image Folder Path :");

        jLabel3.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Image Suffix :");

        jTextArea1.setBackground(new java.awt.Color(51, 51, 51));
        jTextArea1.setColumns(20);
        jTextArea1.setForeground(new java.awt.Color(255, 255, 51));
        jTextArea1.setRows(5);
        jTextArea1.setText("Image folder path[Mandatory] : is where the images to be renamed are present.\nAdd Image prefix[Optional] : is the prefix to be added for the file to be renamed.\nRemove Image prefix[Optional] : Add the prefix to be removed from file name.\nRemove Image suffix[Optional]: Removes the suffix for the images in the folder specified.\nImage suffix [Mandatory] : is the suffix for the image to be renamed.\n");
        jScrollPane1.setViewportView(jTextArea1);

        jLabel4.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Remove Image Prefix :");

        txtRemPrefix.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Remove Image Suffix :");

        txtRemSuffix.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cmbExtension, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnChangeImageName))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(btnInputFolder))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(txtPrefix))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(txtRemPrefix, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(txtRemSuffix, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnInputFolder)
                    .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtPrefix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtRemPrefix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtRemSuffix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnChangeImageName)
                            .addComponent(cmbExtension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnChangeImageNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeImageNameActionPerformed

        if( txtInputFolder.getText().trim().equals("") ) {
            JOptionPane.showMessageDialog(this, "Please select a input folder", "Error", JOptionPane.OK_CANCEL_OPTION);            
        }else if( cmbExtension.getSelectedIndex()==0 ) {
            JOptionPane.showMessageDialog(this, "Please select an extension", "Error", JOptionPane.OK_CANCEL_OPTION);
        } else {
            this.strSuffix = cmbExtension.getSelectedItem().toString();
            this.strPrefix = txtPrefix.getText();
            this.strRemPrefix = txtRemPrefix.getText();            
            this.strRemSuffix = txtRemSuffix.getText();
            start();
        }        
    }//GEN-LAST:event_btnChangeImageNameActionPerformed

    private void btnInputFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputFolderActionPerformed
        // TODO add your handling code here:
        //Handle open button action.
        if (evt.getSource() == btnInputFolder) {
            int returnVal = fc.showOpenDialog(this);
            
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getCurrentDirectory();
                //System.out.println(fc.getSelectedFile().toString());
                this.strFolder = fc.getSelectedFile().toString();
                txtInputFolder.setText(fc.getSelectedFile().toString());
                //This is where a real application would open the file.
                //log.append("Opening: " + fc.getSelectedFile() + "." + newline);
            } else {
                JOptionPane.showMessageDialog(this, "Cancelled");
            }
            //log.setCaretPosition(log.getDocument().getLength());
 
        //Handle save button action.
        } 
    }//GEN-LAST:event_btnInputFolderActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangeImageName;
    private javax.swing.JButton btnInputFolder;
    protected javax.swing.JComboBox cmbExtension;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    protected javax.swing.JTextField txtInputFolder;
    protected javax.swing.JTextField txtPrefix;
    protected javax.swing.JTextField txtRemPrefix;
    protected javax.swing.JTextField txtRemSuffix;
    // End of variables declaration//GEN-END:variables
}
